package deviceCombo

import (
	"context"

	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/ent/device"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/internal/svc"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/internal/utils/dberrorhandler"
	"gitee.com/wenchangshou/simple-admin-pancakebot-rpc/types/pancakebot"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetDeviceComboListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetDeviceComboListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeviceComboListLogic {
	return &GetDeviceComboListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetDeviceComboListLogic) GetDeviceComboList(in *pancakebot.DeviceComboListReq) (*pancakebot.DeviceComboListResp, error) {
	// todo: add your logic here and delete this line
	combos, err := l.svcCtx.DB.Device.Query().Where(device.ID(*in.DeviceId)).QueryCombos().IDs(l.ctx)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, in)
	}
	return &pancakebot.DeviceComboListResp{ComboIds: combos}, nil

}
